package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.AdvertisingEncyclopedia;
import com.jeff.tianti.cms.dto.AdvertisingEncyclopediaQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc AdvertisingEncyclopediaDaoImpl��
 * @date 2019-07-06
 */

public class AdvertisingEncyclopediaDaoImpl extends CustomBaseSqlDaoImpl implements AdvertisingEncyclopediaDaoCustom {

    public PageModel<AdvertisingEncyclopedia> queryAdvertisingEncyclopediaPage(AdvertisingEncyclopediaQueryDTO advertisingEncyclopediaQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from AdvertisingEncyclopedia t where 1= 1 ");
        if (advertisingEncyclopediaQueryDTO != null) {
            String cmsId = advertisingEncyclopediaQueryDTO.getCmsId();
            if (StringUtils.isNotBlank(cmsId) && !"-1".equals(cmsId)) {
                hql.append(" and t.cmsId = :cmsId ");
                map.put("cmsId", cmsId);
            }
            String type = advertisingEncyclopediaQueryDTO.getType();
            if (StringUtils.isNotBlank(type) && !"-1".equals(type)) {
                hql.append(" and t.type = :type ");
                map.put("type", type);
            }
        }
        hql.append(" order by t.createDate desc ");
        return this.queryForPageWithParams(hql.toString(), map, advertisingEncyclopediaQueryDTO.getCurrentPage(), advertisingEncyclopediaQueryDTO.getPageSize());
    }

    public List<AdvertisingEncyclopedia> queryAdvertisingEncyclopediaList(AdvertisingEncyclopediaQueryDTO advertisingEncyclopediaQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from AdvertisingEncyclopedia t where 1 = 1 ");
        if (advertisingEncyclopediaQueryDTO != null) {
            String type = advertisingEncyclopediaQueryDTO.getType();
            if (StringUtils.isNotBlank(type)) {
                hql.append(" and t.type = :type ");
                map.put("type", type);
            }
        }
        hql.append(" order by t.updateDate desc ");
        return this.queryByMapParams(hql.toString(), map);
    }


}